//
//  BWHomeViewController.swift
//  新浪微博
//
//  Created by 冰凌天 on 2017/7/11.
//  Copyright © 2017年 冰凌天. All rights reserved.
//

import UIKit

// 全局常量, 尽量使用 private 修饰
private let cellId = "cellId"

class BWHomeViewController: BWBaseViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }

    /// 列表视图模型
    fileprivate lazy var listViewModel = BWStatusListViewModel()
    
    // 加载数据
    override func loadData() {
        
        // 用 网络工具 加载微博数据
        
        listViewModel.loadStatus(pullup: self.isPullup ) { (isSuccess, shouldRefresh) in
            
            // 结束刷新控件
            self.refreshControl?.endRefreshing()
            // 恢复上拉刷新标记
            self.isPullup = false
            
            if shouldRefresh == true {
                // 刷新表格
                self.tableView?.reloadData()
            }
        }
        
    }
}

// MARK: - 表格数据源方法
extension BWHomeViewController {
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return listViewModel.statusList.count
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath)
        cell.textLabel?.text = listViewModel.statusList[indexPath.row].text
        return cell
    }
    
}

extension BWHomeViewController {
//    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
//        navigationController?.pushViewController(BWDemoViewController(), animated: true)
//    }
    
    override func setupTableView() {
        super.setupTableView()
        
        tableView?.register(UITableViewCell.self, forCellReuseIdentifier: cellId)
        
        
        
        navItem.leftBarButtonItem = UIBarButtonItem.init(title: "好友", highlightedTitle: "好友", normalColor: UIColor.cz_color(withHex: 0x333333), highlightedColor: UIColor.orange, font: nil, target: nil, action: nil)
        
    }
    
    
}



























